package leetcode

/*
 * @lc app=leetcode.cn id=205 lang=golang
 *
 * [205] 同构字符串
 */

// @lc code=start
func isIsomorphic(s string, t string) bool {
	s2t := make(map[byte]byte)
	t2s := make(map[byte]byte)
	for i := 0; i < len(s); i++ {
		ch1, ch2 := s[i], t[i]
		tmp1, ok1 := s2t[ch1]
		tmp2, ok2 := t2s[ch2]
		if (ok1 && !ok2) || (!ok1 && ok2) {
			return false
		} else if !ok1 && !ok2 {
			s2t[ch1] = ch2
			t2s[ch2] = ch1
		} else if tmp1 != ch2 || tmp2 != ch1 {
			return false
		}
	}
	return true
}

// @lc code=end
